﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _1211
{
    class Program
    {
        static void Main(string[] args)
        {
           Serch(@"D:");
            Copy(@"D:\eee", @"D:\bbbbbbb");
        }

        static void Serch(string directory)
        {
            try
            {
                
                string[] files = Directory.GetFiles(directory);//获取当所有文件
                for (int i = 0; i < files.Length; i++)//遍历输出
                {
                    Console.WriteLine(files[i]);
                }
                
                string[] subDirs = Directory.GetDirectories(directory);//获取所有子文件夹

                for (int i = 0; i < subDirs.Length; i++)//对所有子文件夹执行相同的操作
                {
                    Serch(subDirs[i]);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("wrong");
            }
        }


       static void Copy(string sou,string tar)
        {
            using (FileStream ReadFile = new FileStream(sou,FileMode.Open,FileAccess.Read))//读取流
            {
                using (FileStream WriteFile = new FileStream(tar, FileMode.OpenOrCreate, FileAccess.Write))//写入流
                {
                    byte[] buffer = new byte[1024 * 1024 * 5];//定义缓存区大小
                    while (true)
                    {
                        int r = ReadFile.Read(buffer, 0, buffer.Length);//读取
                        if (r==0)
                        {
                            break;
                        }
                        WriteFile.Write(buffer, 0, buffer.Length);//写入
                    }
                }
            }
        }

        }
}
